<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    template="/layout/template.xhtml">

<ui:define name="body">

    <rich:panel>
        <f:facet name="header">StockItems</f:facet>
        
        <a4j:region>
            <h:form>
                <a4j:poll interval="2000" enabled="true" reRender="stockItemListResults" />
            </h:form>
        </a4j:region>
        <a4j:outputPanel layout="block" id="stockItemListResults">
            <h:outputText value="No StockItem exists"
                       rendered="#{empty stockItemList.resultList}"/>

            <h:dataTable id="stockItemList" var="stockItem"
                      value="#{stockItemList.resultList}"
                   rendered="#{not empty stockItemList.resultList}">
                <h:column>
                    <f:facet name="header">Id</f:facet>
                    #{stockItem.id}
                </h:column>
                <h:column>
                    <f:facet name="header">Product</f:facet>
                    <s:link id="product"
                         value="#{stockItem.product.name}"
                         propagation="none"
                         view="/view/stockItem.xhtml">
                        <f:param name="stockItemId"
                                value="#{stockItem.id}"/>
                    </s:link>
                </h:column>
                <h:column>
                    <f:facet name="header">Quantity</f:facet>
                    #{stockItem.product.standardQuantity.quantity} #{stockItem.product.standardQuantity.unit.name}
                </h:column>
                <h:column>
                    <f:facet name="header">Created At</f:facet>
                    #{stockItem.createdAt}
                </h:column>
                <h:column>
                    <f:facet name="header">Updated At</f:facet>
                    #{stockItem.updatedAt}
                </h:column>
            </h:dataTable>

        </a4j:outputPanel>

    </rich:panel>

    <div class="actionButtons">
        <s:button id="done"
               value="Create StockItem"
                view="/view/stockItem.xhtml"/>
    </div>

</ui:define>

</ui:composition>
